package com.project.lk.nurseapp.thermomter;

import android.graphics.Color;
import android.os.Bundle;

import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Description;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.project.lk.nurseapp.R;
import com.project.lk.nurseapp.base.BaseActivity;
import com.project.lk.nurseapp.utils.AppManager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
/**
 * 功能介绍：
 * 项目名：
 * 模块名称：
 * 作者：LK
 * 日期：2018/1/9
 * 修改日期：
 */
public class ThermomterHistoryActivity extends BaseActivity {


    @BindView(R.id.xrecyclerview)
    XRecyclerView xrecyclerview;
    @BindView(R.id.history_chart)
    LineChart historyChart;
    @Override
    protected void initData() {

        YData.add((float) 0);
        setLineChart(false);
    }

    @Override
    protected void initView() {

    }
    List<Float> YData=new ArrayList<>();
    private void setLineChart(boolean isDefault) {
        if (isDefault) {
            if (YData.get(0)==0) {
                YData.remove(0);
            }
        }
        List<Entry> entries = new ArrayList<Entry>();
        for (int i=0;i<YData.size();i++){
            entries.add(new Entry(i,YData.get(i)));
        }
        Description description = new Description();
        description.setText("最近体温记录");//描述文字
        //description.setPosition(50f,50f);//文字位置，默认图表右下角
        description.setTextColor(Color.RED);//描述文字字体颜色
        LineDataSet dataSet = new LineDataSet(entries, "体温记录"); // add entries to dataset
        dataSet.setColor(Color.RED);
        dataSet.setCircleColor(Color.RED);
        dataSet.setDrawValues(false);
        LineData lineData = new LineData(dataSet);
        historyChart.setDescription(description);
        historyChart.setData(lineData);
        historyChart.invalidate(); // refresh
        //获取右边的轴线
        YAxis rightAxis=historyChart.getAxisRight();
        //设置图表右边的y轴禁用
        rightAxis.setEnabled(false);
        XAxis xAxis = historyChart.getXAxis();
        xAxis.setEnabled(true);//设置轴启用或禁用 如果禁用以下的设置全部不生效
        xAxis.setDrawAxisLine(true);//是否绘制轴线
        xAxis.setDrawGridLines(true);//设置x轴上每个点对应的线
        xAxis.setDrawLabels(true);//绘制标签  指x轴上的对应数值
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);//设置x轴的显示位置
        // turn your data into Entry objects

//        thermometerChart.setData(lineData);
    }
    @Override
    protected int getLayoutId() {
        return R.layout.activity_thermomter_history;
    }


    @OnClick(R.id.back)
    public void onViewClicked() {
        AppManager.getAppManager().finishActivity();
    }
}
